<?php

class Index_AuthAction extends C_Action  
{
	public function init()
	{
		session_start();
	}
	public function doAuth()
	{
		$sources = $this->_request->get("sources");
		if(empty($sources))
		{
			$sources = 'sina';
		}
		if($sources == 'sina')
		{
			Weibos::get_Sauth($this->_request);
		}
		else if($sources == 'qq')
		{
			Weibos::get_Qauth($this->_request);
		}
		$url = $this->_request->get("url");
		if(empty($url))
		{
			$url = "http://".$host."/";
		}
		else 
		{
			$url = urldecode($url);
		}
		$this->_response->setRedirect($url);
		
	}
	public function doToken()
	{
		$sources = $this->_request->get("sources");
		if(empty($sources))
		{
			$sources = 'sina';
		}
		$url = $this->_request->get("url");
		$host = $this->_request->getHost();
		$callback_url = "http://".$host."/auth/?sources=$sources&url=".$url;
		if($sources == 'sina')
		{
			$auth_url = Weibos::get_Stoken($callback_url);
		}
		else if($sources == 'qq')
		{
				$auth_url = Weibos::get_Qtoken($callback_url);
		}
		$this->_response->sources = $sources;
		$this->_response->auth_url = $auth_url;
	}
	public function doLogin()
	{
		
	}
	public function doLogout()
	{
		$url = $this->_request->get("url");
		
		unset($_SESSION['id']);
		unset($_SESSION['keys']);
		unset($_SESSION['last_key']);
		$jump_url = urldecode($url);
		if(empty($jump_url))
		{
			$host = $this->_request->getHost();
			$jump_url = "http://".$host."/";
		}
//		Weibos::end_session();
		if(substr_count($jump_url,'admin') > 0)
		{
			$host = $this->_request->getHost();
			$jump_url = "http://".$host."/";
		}
		header("location:$jump_url");
		exit;
	}
}
?>
